<template>
  <div class="result-success">
    <div class="result-container">
      <div class="success-icon">
        <i class="fas fa-check-circle"></i>
      </div>
      <h1 class="result-title">操作成功</h1>
      <div class="result-message">{{ message }}</div>
      <div class="result-actions">
        <button class="btn-primary" @click="goBack">返回上一页</button>
        <button class="btn-secondary" @click="goHome">返回首页</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ResultSuccess',
  data() {
    return {
      defaultMessage: '您的操作已成功完成'
    }
  },
  computed: {
    // 从路由参数获取成功消息，如果没有则使用默认消息
    message() {
      return this.$route.query.message || this.defaultMessage
    },
    
    // 从路由参数获取操作类型
    operationType() {
      return this.$route.query.type || ''
    }
  },
  methods: {
    // 返回上一页
    goBack() {
      // 根据操作类型决定返回的页面
      switch (this.operationType) {
        case 'asset-apply':
          this.$router.push('/new/asset')
          break
        case 'asset-repair':
          this.$router.push('/new/asset')
          break
        case 'material-inbound':
          this.$router.push('/new/material/inventory')
          break
        case 'material-outbound':
          this.$router.push('/new/material/inventory')
          break
        case 'material-inventory':
          this.$router.push('/new/material')
          break
        default:
          this.$router.back()
      }
    },
    
    // 返回首页
    goHome() {
      this.$router.push('/new/home')
    }
  }
}
</script>

<style scoped>
.result-success {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100%;
  padding: 40px 20px;
  background-color: #f5f5f5;
}

.result-container {
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  padding: 40px;
  text-align: center;
  max-width: 600px;
  width: 100%;
}

.success-icon {
  font-size: 72px;
  color: #4caf50;
  margin-bottom: 24px;
}

.result-title {
  font-size: 24px;
  color: #333;
  margin: 0 0 16px 0;
  font-weight: 600;
}

.result-message {
  font-size: 16px;
  color: #666;
  margin-bottom: 32px;
  line-height: 1.5;
}

.result-actions {
  display: flex;
  justify-content: center;
  gap: 16px;
}

.btn-primary {
  background-color: #1976d2;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.btn-primary:hover {
  background-color: #1565c0;
}

.btn-secondary {
  background-color: #f5f5f5;
  color: #333;
  border: 1px solid #ddd;
  padding: 10px 20px;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.btn-secondary:hover {
  background-color: #e0e0e0;
}

@media (max-width: 600px) {
  .result-container {
    padding: 30px 20px;
  }
  
  .result-actions {
    flex-direction: column;
    gap: 12px;
  }
  
  .btn-primary, .btn-secondary {
    width: 100%;
  }
}
</style> 